from openai import OpenAI

client = OpenAI(
    base_url="https://integrate.api.nvidia.com/v1",
    api_key="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"
)

messagesAll = []
while True:
    content = input("请输入你的问题：")
    messagesAll.append({
        "content": content,
        "role": "user"
    })
    completion = client.chat.completions.create(
        model="google/codegemma-7b",
        messages=messagesAll,
        temperature=0.5,
        top_p=1,
        max_tokens=1024,
        stream=True
    )
    reponseMsg = ""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            tempMsg = chunk.choices[0].delta.content
            reponseMsg += tempMsg
            print(tempMsg, end = "")
    messagesAll.append({
        "content": reponseMsg,
        "role": "assistant"
    })
    print()
